Page({
  data: {
    url:'',
    need:''
  },
  onLoad(options){
    const need = wx.getStorageSync('need')
    if(options.param && need){
      const url = options.param;
      this.setData({
        url,
        need
      });
      this.payTo()
    }
  },
  payTo() {
    const { url, need } = this.data;
    const needArr = need.split('|')
    wx.requestMerchantTransfer({
      mchId: needArr[0],
      appId: needArr[1],
      package: needArr[2],
      success: (res) => { 
        /* 处理成功回调 */
        wx.redirectTo({
          url: `/pages/webview/index?src=${url}#wechat_redirect`,
        })
      },
      fail: (e) => { 
        /* 处理失败回调 */
        console.error(e);
        if(e.result == 'cancel' && e.errMsg == 'requestMerchantTransfer:fail:internalerror'){
          wx.redirectTo({
            url: `/pages/webview/index?src=${url}#wechat_redirect`,
          })
          return;
        };
        wx.showModal({
          title: '提示',
          content: JSON.stringify(e),
          showCancel: false,
          success:(res)=>{
            console.log('log---',url)
            // wx.showToast({
            //   icon:'none',
            //   title: url,
            //   duration:100000
            // })
            wx.redirectTo({
              url: `/pages/webview/index?src=${url}#wechat_redirect`,
            })
          }
        })
       }
    });
  },
});
